This tutorial will create a simple Modeler LScript that will rotate and duplicate an object in the currently-active foreground layer.
|
|
First, we begin by creating the script shell that all Modeler LScripts must use. The shell is the name main following by the body of thefunction.
|
|
main { ... } |
|
The first task in our script will be to make a copy of the mesh data that is housed in the currently-active foreground layer(s). We accomplish this by a call to the LScript copy() command. This command will makea copy of the current mesh data on Modeler's internal "clipboard" where we can later pull it back into the active foreground layer using the paste() command.
|
|
main { copy(); ... } |
|
Next, we will initialize our "loop counter." A loop counter is nothing more than a variable that holds a value that represents the current iteration count of a loop. Our loop counter will be a variable called "count", and it will hold the total number of degrees we have travelled so far:
|
|
main { copy(); count = 10; ... } |
|
Because we will be performing a repetitive task in this script, we will use a loop control. Each iteration through the loop will represent one rotation of the object about the axis. We will be using a while() loopcontrol in this script to keep track of how many rotations we have made:
|
|
main { copy(); count = 10; while(count < 360) { ... } } |
|
Each time through our while() loop, we will beperforming several actions. The first will be a rotation of the object that is currently in the Modeler foreground layers by our increment of 10 degrees about the Y axis:
|
|
main { copy(); count = 10; while(count < 360) { rotate(10,"Y"); ... } } |
|
Next, we will recall the mesh data that we placed onto Modeler's internal clipboard usingcopy() . When we paste() thisdata back into the active foreground layers, it will return to the original location from where it was copied:
|
|
main { copy(); count = 10; while(count < 360) { rotate(10,"Y");
|
|
Finally, we will need to increment our loop counter so that we will eventually exceed the value that we are testing for in the while() control loop ( 360 ):
|
|
main { copy(); count = 10; while(count < 360) { rotate(10,"Y");
|
|
If we did not increment the count loop counter, we would plungeModeler into a condition known as an "infinite loop." The while() loopwould never stop, because count would never exceed or equal 360(it would always be 10, the value we initialized it with). The script would never return, and you would be forced to terminate Modeler.
|